<?php
namespace app\admin\controller;
use think\Session;
use think\Controller;
class Login extends Controller
{
    public function login()
    {
        Session::delete('user');
        Session::delete('id');
        return view();
    }
    public function checklog(){
        $data['user'] = input('post.user' , '' , 'htmlspecialchars');
        $data['pwd'] = md5(input('post.pwd' , '' , 'trim'));
        $log = db('admin')->where($data)->find();
        if($log){
            session('nickname' , $log['nickname']);
            session('id' , $log['id']);

            $role = db('admin_role')->where('admin_id', session('id'))->find();
            session('role_id' , $role["role_id"]); 
            $role = db('role_permission')->where('role_id', $role["role_id"])->select();
            $permission_id=[];
            foreach ($role as $key => $value) {
                $permission_id[]=$role[$key]['permission_id'];
            }
            $permission_id=implode(',', $permission_id);
            session('permission_id' , $permission_id);
            $this->success('登录成功' , url('index/index') );
        }else{
            $this->error('登录失败');
        }
    }
}
